<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/18 0018
 * Time: 上午 11:19
 */

namespace App\Http\Admin\Customer\Controllers;

use Framework\BaseClass\Http\Admin\Controller;
use App\Http\Admin\Website\Models\Menu;
use App\Eloquent\Ygt\ProductCustomer;
use App\Eloquent\Ygt\Category;

class ProductController extends Controller
{
    protected $modelName = 'ProductCustomer';
    protected $company = false;

    protected $rules = [
//        'customer_name' => 'bail|required',
//        'sort_id' => 'required',
    ];

    public function __construct()
    {
        parent::__construct();
        $this->model = new ProductCustomer();

    }

    protected function _where()
    {
        return [
            'customer_id'=>request('customer_id')
        ];
    }

    protected function _orderby(){
        return ['ygt_product.id', 'desc'];
    }

    protected function _join(){
        $join = [
            ['table' => 'ygt_product', 'field_l' => 'ygt_product.id', 'field_c' => '=', 'field_r' => 'ygt_product_customer.product_id'],
        ];
        return $join;
    }
    protected function _vdata()
    {
        $adminUser = request()->user('admin')->toArray();
        $company_id = $adminUser['company_id'];

        $categoryModel = new Category();
        $category = $categoryModel->getCategoryOption(0,$company_id);
        $catelist = [];
        foreach ($category as $k => $v) {
            $catelist[$v['id']] = str_repeat('└―', $v['level']) . $v['cat_name'];
        }
        $optionHtml = '';
        foreach ($catelist as $k => $v) {
            $optionHtml .= '<option value="' . $k . '">' . $v . '</option>';
        }
        $catejson = json_encode($catelist);

        $customerId = request('customer_id');

        return compact('catejson', 'optionHtml', 'customerId');
    }
}